package com.wsm.springcloud_compose.compose_user_produce.business.impl;

import com.wsm.springcloud_compose.compose_user_bean.response.SysUsersResponse;
import com.wsm.springcloud_compose.compose_user_produce.business.UserBiz;
import com.wsm.springcloud_compose.compose_user_produce.domain.SysPermissions;
import com.wsm.springcloud_compose.compose_user_produce.domain.SysRoles;
import com.wsm.springcloud_compose.compose_user_produce.domain.SysUsers;
import com.wsm.springcloud_compose.compose_user_produce.service.UserSerice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @name: UserBizImpl
 * @Author: wangshimin
 * @Date: 2019/11/20  10:49
 * @Description:
 */
@Slf4j
@Service
public class UserBizImpl implements UserBiz {
    @Autowired
    UserSerice userSerice;

    @Override
    public SysUsersResponse login(String userName) {
        SysUsers login = userSerice.login(userName);
        SysUsersResponse sysUsersResponse = new SysUsersResponse();
        if (null != login) {
            sysUsersResponse = new SysUsersResponse(login.getId(), login.getUsername(), login.getPassword(), login.getSalt(), login.getRoleId(), login.getLocked());

        }
        return sysUsersResponse;
    }

    @Override
    public List<SysRoles> getRolesById(long id) {
        return userSerice.selectRoleByUser(id);
    }

    @Override
    public List<SysPermissions> getPermissionsById(long id) {
        return userSerice.selectPermissionsByUser(id);
    }
}
